var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
    })(t, e);
}, function(t, e) {
    function a() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (a.prototype = e.prototype, 
    new a());
}), a = this && this.__decorate || function(t, e, o, a) {
    var n, i = arguments.length, s = i < 3 ? e : null === a ? a = Object.getOwnPropertyDescriptor(e, o) : a;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(t, e, o, a); else for (var l = t.length - 1; 0 <= l; l--) (n = t[l]) && (s = (i < 3 ? n(s) : 3 < i ? n(e, o, s) : n(e, o)) || s);
    return 3 < i && s && Object.defineProperty(e, o, s), s;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("HpView"), s = e("PersonView"), c = e("Global"), l = e("AudioManager"), d = e("PetManager"), u = e("MyScrollView"), p = e("SkinItemView"), h = e("TimeView"), f = e("SkinView"), g = e("GameConfig"), m = e("GameData"), y = e("DataManager"), v = e("LoadManager"), w = e("UIManager"), b = e("WebManager"), P = cc._decorator, I = P.ccclass, G = P.property, _ = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.shadow = null, t.box = null, t.egg = null, t.before = null, t.after = null, 
        t.light = null, t.toggleContainer = null, t.timeView = null, t.upBtn = null, t.evolveBtn = null, 
        t.changeBtn = null, t.progress = null, t.lastPet = null, t.lastRankLabel = null, 
        t.nextPet = null, t.nextRankLabel = null, t.diamondSprite = null, t.diamondLabel = null, 
        t.tipsLabel = null, t.costLabel = null, t.dLabel = null, t.atkLabel = null, t.speLabel = null, 
        t.hpLabel = null, t.numLabel = null, t.up = null, t.down = null, t.diamond = 50, 
        t.piece = 80, t.value = {
            atk: 0,
            spe: 0,
            hp: 0
        }, t.nums = [], t.ups = [], t.downs = [], t.numPool = new cc.NodePool(), t.upPool = new cc.NodePool(), 
        t.downPool = new cc.NodePool(), t.idx = -1, t;
    }
    return i(t, e), t.prototype.onEnable = function() {
        var t = this;
        d.default.getInstance().isHas(1) || cc.systemEvent.on("hatch_refresh", function() {
            cc.systemEvent.off("hatch_refresh"), 1 < t.toggleContainer.toggleItems.length && t.toggleContainer.toggleItems[1].getComponent(p.default).initPet({
                type: f.SkinItemType.PET,
                rank: 1
            }), 1 == t.idx && t.refresh(t.idx);
        });
    }, t.prototype.onDisable = function() {
        cc.systemEvent.off("hatch_refresh");
    }, t.prototype.onToggle = function(t) {
        t = t.getComponent(p.default).__itemID;
        this.refresh(t);
    }, t.prototype.onClickCode = function() {
        var t, e;
        if (l.default.getInstance().playAudio("按钮2"), b.default.getInstance().sentLog("点击宠物界面兑换按键"), 
        m.GD.piece < g.GC.hatchConfig.piece) return b.default.getInstance().sentLog("触发碎片不足"), 
        void (m.GD.pieceCount < g.GC.maxPieceCount && c.G.platform != c.Platform.XiaoDu ? w.default.getInstance().loadPopPnl("piece", {
            num: g.GC.pieceNum,
            view: this
        }) : GA.PA && GA.PA.showToast ? null === (e = null === (t = GA.PA) || void 0 === t ? void 0 : t.showToast) || void 0 === e || e.call(t, {
            title: "碎片不足",
            icon: "none"
        }) : w.default.getInstance().showToast({
            str: "碎片不足"
        }));
        1 == this.idx && 0 == m.GD.hatchLastTime && (b.default.getInstance().sentLog("触发机甲暴龙兑换"), 
        m.GD.piece -= g.GC.hatchConfig.piece, y.default.getInstance().save(), cc.systemEvent.emit("hatch_timer"), 
        this.before.active = !1, this.after.active = !0, this.timeView.init(g.GC.hatchConfig.time), 
        this.timeView.startTimer());
    }, t.prototype.onClickChange = function() {
        l.default.getInstance().playAudio("按钮2"), b.default.getInstance().sentLog("点击宠物界面替换上阵按键"), 
        m.GD.petDataIdx != this.idx && (m.GD.petDataIdx = this.idx, this.setValue(this.getValue(m.GD.petDataIdx, d.default.getInstance().getRealData().lv)), 
        this.refresh(m.GD.petDataIdx), this.changeBtn.interactable = !1);
    }, t.prototype.onClickUp = function() {
        var t;
        l.default.getInstance().playAudio("按钮2"), b.default.getInstance().sentLog("点击宠物界面强化按键");
        var e = d.default.getInstance().getConfig(this.idx);
        if (e.costType == c.RewardType.PIECE) {
            if (m.GD.piece < this.piece) return b.default.getInstance().sentLog("触发碎片不足"), void (m.GD.pieceCount < g.GC.maxPieceCount && c.G.platform != c.Platform.XiaoDu ? w.default.getInstance().loadPopPnl("piece", {
                num: g.GC.pieceNum,
                view: this
            }) : GA.PA && GA.PA.showToast ? null === (t = null === (o = GA.PA) || void 0 === o ? void 0 : o.showToast) || void 0 === t || t.call(o, {
                title: "碎片不足",
                icon: "none"
            }) : w.default.getInstance().showToast({
                str: "碎片不足"
            }));
        } else if (m.GD.diamond < this.diamond) return void (c.G.platform != c.Platform.XiaoDu ? w.default.getInstance().loadPopPnl("diamond", {
            num: 100,
            view: this
        }) : w.default.getInstance().showToast({
            str: "钻石不足"
        }));
        var o = d.default.getInstance().getRealData(this.idx);
        o.lv < 99 && (e.costType == c.RewardType.PIECE ? m.GD.piece -= this.piece : m.GD.diamond -= this.diamond, 
        o.lv++, d.default.getInstance().setRealData(o, this.idx), this.setValue(this.getValue(this.idx, o.lv)), 
        this.refresh(this.idx), w.default.getInstance().barViews.forEach(function(t) {
            return t.refresh();
        }), y.default.getInstance().save({
            interval: 5e3
        }));
    }, t.prototype.onClickEvolve = function() {
        l.default.getInstance().playAudio("按钮2"), b.default.getInstance().sentLog("点击宠物界面进化按键"), 
        this.doEvolve();
    }, t.prototype.doEvolve = function() {
        var t = d.default.getInstance().getRealData(this.idx), e = d.default.getInstance().getConfig(this.idx);
        t.form < e.form ? (t.form++, this.doEffect(this.idx), y.default.getInstance().save(), 
        b.default.getInstance().sentLogs([ {
            eventId: "点击皮肤界面进化按键"
        }, {
            eventId: "获得宠物" + e.m + "第" + (t.form + 1) + "阶段"
        } ])) : null === (t = null === (e = GA.PA) || void 0 === e ? void 0 : e.showToast) || void 0 === t || t.call(e, {
            title: "该宠暂时无法进化",
            icon: "none"
        });
    }, t.prototype.start = function() {
        var t;
        this.progress.x = 1, this.setValue(this.getValue(m.GD.petDataIdx, d.default.getInstance().getRealData().lv)), 
        this.refresh(m.GD.petDataIdx), this.costLabel.string = g.GC.hatchConfig.piece.toString(), 
        !d.default.getInstance().isHas(1) && 0 < m.GD.hatchLastTime && (t = Math.floor((Date.now() - m.GD.hatchLastTime) / 1e3), 
        cc.log("offectTime", t), t < g.GC.hatchConfig.time && (this.before.active = !1, 
        this.after.active = !0, this.timeView.init(g.GC.hatchConfig.time - t), this.timeView.startTimer()));
    }, t.prototype.doEffect = function(t) {
        var e = this;
        void 0 === t && (t = this.idx), this.shadow.active = !0, cc.tween(this.shadow).to(.5, {
            opacity: 255
        }).start();
        var o = d.default.getInstance().getRealData(t);
        cc.tween(this.lastPet.node).by(.5, {
            position: cc.v3(250, 0)
        }).call(function() {
            e.lastPet.initPet(d.default.getInstance().getPetIdx(t, o.form), function() {
                0 == t ? (e.lastPet.skeleton.setAnimation(0, "move3", !1), e.lastPet.skeleton.setEventListener(function(t, e) {
                    "heti" == e.data.name ? l.default.getInstance().playAudio("狗组合部件音效") : "guangquan" == e.data.name && (l.default.getInstance().playAudio("狗组合部件音效"), 
                    l.default.getInstance().playAudio("光圈出现音效"));
                })) : 1 == t && (e.lastPet.skeleton.setAnimation(0, 2 == o.form || 102 == c.G.tryPetIdx ? "move4" : "move3", !1), 
                l.default.getInstance().playAudio("宠物孵化动画音效")), e.lastPet.skeleton.setCompleteListener(function() {
                    e.refresh(t), e.lastPet.skeleton.setEventListener(null), e.lastPet.skeleton.setCompleteListener(null), 
                    cc.tween(e.lastPet.node).by(.5, {
                        position: cc.v3(-250, 0)
                    }).call(function() {
                        e.lastPet.skeleton.setAnimation(0, "move2", !0);
                    }).start(), e.nextPet.node.setPosition(cc.v2(425, 5)), cc.tween(e.nextPet.node).to(.5, {
                        opacity: 255
                    }).start(), cc.tween(e.shadow).to(.5, {
                        opacity: 0
                    }).call(function() {
                        e.shadow.active = !1;
                    }).start();
                });
            });
        }).start(), cc.tween(this.nextPet.node).parallel(cc.tween().by(.5, {
            position: cc.v2(-250, 0)
        }), cc.tween().to(.5, {
            opacity: 0
        })).start();
    }, t.prototype.refresh = function(t) {
        var e, o, a, n, i = this;
        void 0 === t && (t = m.GD.petDataIdx), this.idx = t, 1 != this.idx || d.default.getInstance().isHas(1) ? (this.box.active = !0, 
        this.egg.active = !1, e = d.default.getInstance().getRealData(t), o = d.default.getInstance().getConfig(t), 
        n = (a = e.form < c.G.petEvolve.length ? c.G.petEvolve[e.form] : c.G.petMaxLevel) - e.lv, 
        this.refreshPet(d.default.getInstance().getPetIdx(t, e.form), e.lv, a), this.refreshBtn(n, e.lv), 
        this.refreshProgress(n, e.form), this.removeAll(), this.refreshLabel(this.getValue(t, e.lv)), 
        this.showLabel(this.getValue(t, e.lv + 1)), n = 1 == d.default.getInstance().isHas(t), 
        this.upBtn.interactable = n, this.evolveBtn.interactable = n, this.changeBtn.interactable = n && m.GD.petDataIdx != t, 
        1 == this.idx ? this.light.active = !0 : this.light.active = !1, o.costType == c.RewardType.DIAMOND ? (this.diamond = Math.ceil(o.costBase * Math.pow(o.costPow, e.lv)), 
        this.diamondLabel.string = GA.formatNumber(this.diamond), v.default.getInstance().loadSpriteFrame({
            url: "image/ui/钻石2@2x",
            sprite: this.diamondSprite,
            success: function() {
                i.diamondSprite.node.scale = 1;
            }
        })) : (this.piece = Math.ceil(o.costBase * Math.pow(o.costPow, e.lv)), this.diamondLabel.string = GA.formatNumber(this.piece), 
        v.default.getInstance().loadSpriteFrame({
            url: "image/ui/碎片@2x",
            sprite: this.diamondSprite,
            success: function() {
                i.diamondSprite.node.scale = .4;
            }
        }))) : (this.box.active = !1, this.egg.active = !0, this.refreshTime());
    }, t.prototype.refreshPet = function(t, e, o) {
        this.lastPet.initPet(t), this.lastRankLabel.string = "LV " + e, this.nextPet.initPet(t + 1), 
        this.nextRankLabel.string = "LV " + o;
    }, t.prototype.refreshBtn = function(t, e) {
        0 < t ? (this.tipsLabel.string = "还差       级进化", this.dLabel.node.active = !0, this.dLabel.string = t.toString(), 
        this.upBtn.node.active = !0, this.evolveBtn.node.active = !1) : e < c.G.petMaxLevel ? (this.tipsLabel.string = "进化你的宠物", 
        this.dLabel.node.active = !1, this.upBtn.node.active = !1, this.evolveBtn.node.active = !0, 
        this.evolveBtn.interactable = !0) : (this.tipsLabel.string = "进化已达上限", this.dLabel.node.active = !1, 
        this.upBtn.node.active = !1, this.evolveBtn.node.active = !0, this.evolveBtn.interactable = !1);
    }, t.prototype.refreshProgress = function(t, e) {
        e < c.G.petEvolve.length && (e = e <= 0 ? 0 < c.G.petEvolve.length ? c.G.petEvolve[e] : c.G.petMaxLevel : c.G.petEvolve[e] - c.G.petEvolve[e - 1], 
        this.progress.init(e), this.progress.refresh(e - t));
    }, t.prototype.refreshTime = function() {
        var t;
        d.default.getInstance().isHas(1) || (t = Math.floor((Date.now() - m.GD.hatchLastTime) / 1e3)) < g.GC.hatchConfig.time && (this.before.active = !1, 
        this.after.active = !0, this.timeView.num = g.GC.hatchConfig.time - t, this.timeView.refresh());
    }, t.prototype.setValue = function(t) {
        this.value = t;
    }, t.prototype.getValue = function(t, e) {
        return {
            atk: d.default.getInstance().getAtk(t, e),
            spe: d.default.getInstance().getIdle(t, e),
            hp: d.default.getInstance().getHp(t, e)
        };
    }, t.prototype.refreshLabel = function(t) {
        void 0 === t && (t = this.value), this.atkLabel.string = t.atk.toString(), this.speLabel.string = t.spe.toFixed(1), 
        this.hpLabel.string = t.hp.toString();
    }, t.prototype.showLabel = function(t) {
        (t = void 0 === t ? this.value : t).atk != this.value.atk && this.append(t.atk - this.value.atk, this.atkLabel.node.parent), 
        t.spe != this.value.spe && this.append(Math.round(10 * (t.spe - this.value.spe)) / 10, this.speLabel.node.parent), 
        t.hp != this.value.hp && this.append(t.hp - this.value.hp, this.hpLabel.node.parent);
    }, t.prototype.append = function(t, e) {
        var o, a = this.getNum();
        a.parent = e, a.setPosition(cc.v2(200, 0)), this.nums.push(a), 0 < t ? (a.color = cc.Color.GREEN, 
        a.getComponent(cc.Label).string = "+" + t, (o = this.getUp()).parent = e, o.setPosition(cc.v2(250, 0)), 
        this.ups.push(o)) : (a.color = cc.Color.RED, a.getComponent(cc.Label).string = "" + t, 
        (t = this.getDown()).setPosition(cc.v2(250, 0)), t.parent = e, this.downs.push(t));
    }, t.prototype.removeAll = function() {
        for (;0 < this.nums.length; ) this.numPool.put(this.nums.pop());
        for (;0 < this.ups.length; ) this.upPool.put(this.ups.pop());
        for (;0 < this.downs.length; ) this.downPool.put(this.downs.pop());
    }, t.prototype.getNum = function() {
        return 0 < this.numPool.size() ? this.numPool.get() : cc.instantiate(this.numLabel.node);
    }, t.prototype.getUp = function() {
        return 0 < this.upPool.size() ? this.upPool.get() : cc.instantiate(this.up);
    }, t.prototype.getDown = function() {
        return 0 < this.downPool.size() ? this.downPool.get() : cc.instantiate(this.down);
    }, a([ G(cc.Node) ], t.prototype, "shadow", void 0), a([ G(cc.Node) ], t.prototype, "box", void 0), 
    a([ G(cc.Node) ], t.prototype, "egg", void 0), a([ G(cc.Node) ], t.prototype, "before", void 0), 
    a([ G(cc.Node) ], t.prototype, "after", void 0), a([ G(cc.Node) ], t.prototype, "light", void 0), 
    a([ G(cc.ToggleContainer) ], t.prototype, "toggleContainer", void 0), a([ G(h.default) ], t.prototype, "timeView", void 0), 
    a([ G(cc.Button) ], t.prototype, "upBtn", void 0), a([ G(cc.Button) ], t.prototype, "evolveBtn", void 0), 
    a([ G(cc.Button) ], t.prototype, "changeBtn", void 0), a([ G(r.default) ], t.prototype, "progress", void 0), 
    a([ G(s.default) ], t.prototype, "lastPet", void 0), a([ G(cc.Label) ], t.prototype, "lastRankLabel", void 0), 
    a([ G(s.default) ], t.prototype, "nextPet", void 0), a([ G(cc.Label) ], t.prototype, "nextRankLabel", void 0), 
    a([ G(cc.Sprite) ], t.prototype, "diamondSprite", void 0), a([ G(cc.Label) ], t.prototype, "diamondLabel", void 0), 
    a([ G(cc.Label) ], t.prototype, "tipsLabel", void 0), a([ G(cc.Label) ], t.prototype, "costLabel", void 0), 
    a([ G(cc.Label) ], t.prototype, "dLabel", void 0), a([ G(cc.Label) ], t.prototype, "atkLabel", void 0), 
    a([ G(cc.Label) ], t.prototype, "speLabel", void 0), a([ G(cc.Label) ], t.prototype, "hpLabel", void 0), 
    a([ G(cc.Label) ], t.prototype, "numLabel", void 0), a([ G(cc.Node) ], t.prototype, "up", void 0), 
    a([ G(cc.Node) ], t.prototype, "down", void 0), a([ I ], t);
}(u.default);

n.default = _;